<?php

defined('SYSPATH') or die('Access error!');

class Model_Collect extends Model
{

    public function get_collect_list($data)
    {
        $where = ' WHERE ';
        if(Arr::validate_arr($data)){
            $where .= $this->get_where($data);
        }
        $where .= " ORDER BY id DESC";
        $sql = " SELECT * FROM " . $this->table . $where;

        $collect_list_temp = $this->get_page_list($sql, 10);
        $collect_list['list'] = array();
        if (Arr::validate_arr($collect_list_temp['list']))
        {
            foreach ($collect_list_temp['list'] as $value)
            {
                $value['url'] = $this->create_collect_url($value['type'], $value['item_id']);
                $collect_list['list'][] = $value;
            }
        }
        $collect_list['page'] = $collect_list_temp['page'];
        unset($collect_list_temp);
        return $collect_list;
    }

    public function create_collect_url($type,$id)
    {
        switch ($type)
        {
            case 'goods':
                return Model::factory('shop_goods')->create_goods_url($id);
                break;
            case 'store':
                return Model::factory('shop_store')->create_store_url($id);
                break;
             case 'news':
                return Url::site('shopnews/detail/'.$id);
                break;
             case 'trade':
                return Url::site('trade/detail/'.$id);
                break;
            case 'q2a':
                return Url::site('question/detail/'.$id);
                break;
            default:
                break;
        }
    }

}